// 时间格式化
export const formatTime = (date: Date) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return (
    [year, month, day].map(formatNumber).join('/') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}

// 格式化数字
const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}

/**
 * 判定是否为空的方法
 * @param argu 参数
 */
export const IsEmpty = (argument: any) => {
  if (typeof argument === 'object') {
    const _keys: any[] = Object.keys(argument);
    if (_keys?.length) {
      return false;
    }
    return true;
  } else {
    return argument === '' || argument === null || argument === undefined;
  }
}

/**
 * 递归判定对象并执行操作
 * @param object 对象
 * @function fn 判定是否为空的方法
 */
export function RecursionObject<T>(object: T, fn: (argu: any) => boolean): void {
  for (const key in object) {
    if (typeof object[key] === 'object') {
      RecursionObject(object[key], fn); // 递归调用
    }
    if (fn(object[key])) {
      delete object[key]; // 如果满足条件，删除属性
    }
  }
}